<meta charset="utf-8"/>
<div class="row">
  <div class="col-xs-12">
    <div class="row">
      <div class="col-xs-12">
        <div style="height:36px;margin-top:2px">
          <table class="no-border" style="display:inline">
            <tr>
              <td permission='order_manage_btn_listData' style="padding-right:6px;display:none">
                购买人
              </td>
              <td permission='order_manage_btn_listData' style="display:none">
                <input type="text" id="key_buyer" class="form-control search-query" placeholder="输入购买人账号" style="width:158px"/>
              </td>
              <td permission='order_manage_btn_listData' style="padding-right:6px;display:none">
                收款人
              </td>
              <td permission='order_manage_btn_listData' style="display:none">
                <input type="text" id="key_payee" class="form-control search-query" placeholder="输入收款人账号" style="width:158px"/>
              </td>
              <td permission='order_manage_btn_listData' style="padding-right:6px;display:none">
                订单号
              </td>
              <td permission='order_manage_btn_listData' style="display:none">
                <input type="text" id="key_out_trade_no" class="form-control search-query" placeholder="输入订单号" style="width:158px"/>
              </td>
              <td permission='order_manage_btn_listData' style="padding-right:6px;padding-left:6px;display:none">
                下单时间
              </td>
              <td permission='order_manage_btn_listData' style="display:none" class="hidden-480">
                <input type="text" id="key_add_time_start" placeholder="起始日期时间" readonly class="form-control search-query" maxlength="19" style="width:144px;cursor:pointer" title="请选择兑换时间起始时间"/>
              </td>
              <td permission='order_manage_btn_listData' style="display:none" class="hidden-480">
                <i class='fa fa-exchange'></i>
              </td>
              <td permission='order_manage_btn_listData' style="display:none" class="hidden-480">
                <input type="text" id="key_add_time_end" placeholder="结束日期时间" readonly class="form-control search-query" maxlength="19" style="width:144px;cursor:pointer" title="请选择兑换时间结束时间"/>
              </td>
              <td permission='order_manage_btn_listData' style="display:none">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnSearch" title="搜索查询"><span class="ace-icon fa fa-search bigger-110"></span>搜索</button></span>
                </div>
              </td>
              <td permission='order_manage_btn_listData' style="display:none" class="hidden-480">
                <div class="input-group">
                  <span class="input-group-btn"><button type="button" class="btn btn-inverse btn-white" id="btnReset" title="重置清空搜索关键字"><span class="ace-icon fa fa-undo bigger-110"></span>重置</button></span>
                </div>
              </td>
            </tr>
          </table>
          <div class="hidden-480 pull-right tableTools-container" permission='order_manage_btn_listData' style="display:none;margin-bottom:2px"></div>
        </div>
        <table id="tableListGoodsOrder" class="table table-striped table-bordered table-hover">
          <tbody>
          <tr>
            <td style="text-align:center;height:37px">正在加载……</td>
          </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<div id="div_goods_order_edit" style="display:none;padding-top:2px">
  <form class="form-horizontal" id="form_goods_order_edit" role="form">
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">购买人|付费用户id<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="user_id" placeholder="购买人|付费用户id" class="form-control" maxlength="19" title="购买人|付费用户id"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <div class="input-group" title="选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）">
        <span class="input-group-btn">
          <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle col-sm-12" style="margin-left:0px;">
            <span id="dropdownLabel_buyer_type">选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）</span>
            <i class="ace-icon fa fa-angle-down"></i>
          </button>
          <ul class="dropdown-menu col-sm-12">
            <li>
              <a id="buyer_type_" href="javascript:winFn.dropdown('#buyer_type','','#dropdownLabel_buyer_type','选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）');">选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）</a>
            </li>
            <li>
              <a id="buyer_type1" href="javascript:winFn.dropdown('#buyer_type','1','#dropdownLabel_buyer_type','是用户购买');">是用户购买</a>
            </li>
            <li>
              <a id="buyer_type2" href="javascript:winFn.dropdown('#buyer_type','2','#dropdownLabel_buyer_type','是直营店向区级购买');">是直营店向区级购买</a>
            </li>
            <li>
              <a id="buyer_type3" href="javascript:winFn.dropdown('#buyer_type','3','#dropdownLabel_buyer_type','区级向总公司购买');">区级向总公司购买</a>
            </li>
          </ul>
          <input id="buyer_type" maxlength="1" type="hidden"/>
        </span>
      </div>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">微信的openId<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="openId" placeholder="微信的openId" class="form-control" maxlength="40" title="微信的openId"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">交易标识码（交易单号）</div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="transaction_id" placeholder="交易标识码（交易单号）" class="form-control" maxlength="64" title="交易标识码（交易单号）"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">订单号<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="out_trade_no" placeholder="订单号" class="form-control" maxlength="19" title="订单号"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">支付金额<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="total_fee" placeholder="支付金额" class="form-control" maxlength="15" oninput="value=value.replace(/[^\d.]/g,'')" title="支付金额"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">支付状态(0未支付;1已支付)<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="status" placeholder="支付状态(0未支付;1已支付)" class="form-control" maxlength="1" title="支付状态(0未支付;1已支付)"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">评价状态(0待评价;1已评价)<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="evaluate" placeholder="评价状态(0待评价;1已评价)" class="form-control" maxlength="1" title="评价状态(0待评价;1已评价)"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">退款状态(0未退款;1已退款)<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="refund" placeholder="退款状态(0未退款;1已退款)" class="form-control" maxlength="1" title="退款状态(0未退款;1已退款)"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">版本号(乐观锁)<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="version" placeholder="版本号(乐观锁)" class="form-control" maxlength="10" title="版本号(乐观锁)"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">支付描述（下单描述）<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="body" placeholder="支付描述（下单描述）" class="form-control" maxlength="128" title="支付描述（下单描述）"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">付款日期（支付成功后更新）</div></label>
    <div class="col-sm-7">
      <div class="hr-4"></div>
      <input type="text" id="pay_date" placeholder="付款日期（支付成功后更新）" class="form-control" maxlength="10" title="付款日期（支付成功后更新）"/>
    </div>
    <label class="col-sm-3 control-label no-padding-right"><div class="hr-4">下单时间<span style="color:#f00;display:inline-block;vertical-align:middle;width:auto;height:14px;line-height:18px">*</span></div></label>
    <div class="col-sm-7" style="margin-bottom:6px">
      <div class="hr-4"></div>
      <input type="text" readonly id="add_date" placeholder="请选择下单时间" class="form-control" maxlength="10" title="请选择下单时间" style="cursor:pointer"/>
    </div>
  </form>
</div>
<div id="div_order_info" style="display:none;padding-top:2px;margin-bottom:-20px;">
  <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"></div>
</div>
<div id="div_list_coupon" style="display:none;">
  <table id="table_coupon_list" class="tabletrtd">
    <thead>
      <tr>
        <th style="width:150px;" class="text-center">开始时间</th>
        <th style="width:150px;" class="text-center">结束时间</th>
        <th style="width:88px;" class="text-center">核销状态</th>
        <th style="width:88px;" class="text-center">兑换状态</th>
        <th style="width:100px;" class="text-center">选项</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td colspan="5" class="text-center">正在加载……</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="divKeyColumns" style="display:none;padding:1px 0px;"></div>
<div style="display:none;">
  <input type="hidden" id="order_manage_btn_listData"/>
  <input type="hidden" id="order_manage_row_edit"/>
  <input type="hidden" id="order_manage_row_queryById"/>
  <input type="hidden" id="order_manage_row_delById"/>
  <input type="hidden" id="order_manage_btn_delByKeys"/>
</div>
<script type="text/javascript">
  ;(function($){
    var tableDom = '#tableListGoodsOrder';
    var urlRoute = '/goodsOrder/';/*请求controller层的url*/
    var getList = urlRoute + 'listData';/*获取数据列表*/
    var urlAdd = urlRoute + 'add';/*添加*/
    var urlEdit = urlRoute + 'edit';/*编辑*/
    var urlQueryById = urlRoute + 'queryById';/*根据id查询对应的数据*/
    var getOrderCouponList = urlRoute + 'listOrderCoupon';/*查询优惠券列表*/
    var urlAvailable = urlRoute + 'updateAvailable';/*查询优惠券列表*/
    var stateOriginal = {};//仅供参考，更新优化-选项1,可参考项目law-frontend的页面serviceAd.html和后端law-backend的ServiceADService.java;记录编辑的值,仅在编辑时可用
    var thisTable = null;
    thisPage = {
      init : function(){
        this.initTable();
        this.createDropdown();
        this.initDom();
        this.addEvent();
      },
      initDom : function(){
        laydate.render({
          elem: '#add_date',//指定元素
          format : 'yyyy-MM-dd HH:mm:ss',/*格式*/
          showBottom : true,/*是否显示底部栏*/
          type: 'datetime'/*格式,datetime|date|time*/
        });
        laydate.render({
          elem: '#key_add_time_start',//指定元素
          format : 'yyyy-MM-dd HH:mm:ss',/*格式*/
          showBottom : true,/*是否显示底部栏*/
          type: 'datetime'/*格式,datetime|date|time*/
        });
        laydate.render({
          elem: '#key_add_time_end',
          format : 'yyyy-MM-dd HH:mm:ss',/*格式*/
          showBottom : true,/*是否显示底部栏*/
          type: 'datetime'/*格式,datetime|date|time*/
        });
      },
      createDropdown: function(){
      },
      addEvent: function(){
        $('#btnAdd').on('click', function(){
          thisPage.edit();
        });
        //搜索按钮
        $('#btnSearch').on('click', function(){
          thisPage.search();
        });
        //重置按钮
        $('#btnReset').on('click', function(){
          $('#key_payee').val('');
          $('#key_buyer').val('');
          $('#key_out_trade_no').val('');
          $('#key_status').val('');
        });
        //按钮组-自定义显示列
        $('#iconColumn').parent().parent().on('click', function(){
          pageDataTable.columnCustom(thisTable, tableDom,'#divKeyColumns');
        });
        //按钮组-搜索
        $('#iconRefresh').parent().parent().on('click', function(){
          thisPage.search();
        });
        $('#btnDel').on('click', function(){
          thisPage.delKeys();
        });
      },
      /**获取已选中的主键集合,用法:var kids = thisPage.getKeyIds();if(kids == null){layerFn.alert('请选择要操作的数据', AppKey.code.code199);return;}*/
      getKeyIds : function(){
        var arrays = thisTable.rows({selected : true}).data();//获取已勾选的数据行
        if(arrays.length == 0){
          return null;
        }
        var kids = '';
        for(var i = 0; i < arrays.length; i++){
          var value = arrays[i].kid;
          if(value != ''){
            if(kids.length > 0) kids += ",";
            kids += value;
          }
        }
        return kids;
      },
      initTable : function(){
        var optsVisible = getOptsVisible('order_manage_row');//确定是否要显示操作选项
        var optsBatchBtn = getOptsVisible('order_manage_btn_delByKeys');//是否有批量操作的权限,若是多个按钮权限时以逗号,隔开
        var aoColumns = [];
        aoColumns.push({
          data : "kid",
          sortable : false,
          width : "36px",
          class : "center",
          visible : true,
          title : '<label title="序号" style="color:#000;font-size:13px;font-weight:normal">序号</label>'
        });
        aoColumns.push({
          data : "user_name",
          sortable : true,
          title : "下单人账号"
        });
        aoColumns.push({
          data : "payee",
          sortable : true,
          title : "收款人"
        });
        aoColumns.push({
          data : "real_name",
          sortable : false,
          title : "收款人姓名"
        });
        aoColumns.push({
          data : "out_trade_no",
          sortable : false,
          title : "订单号"
        });
        aoColumns.push({
          data : "total_fee",
          sortable : false,
          title : "支付金额"
        });
        aoColumns.push({
          data : "buyer_type",
          sortable : true,
          title : "购买类型",
          render : function(value){
            if(value == 1){
              return "消费者购买";
            }else if(value == 2){
              return "门店采购";
            }else if(value == 3){
              return "区代采购";
            }else{
              return "";
            }
          }
        });
        aoColumns.push({
          data : "status",
          sortable : true,
          title : "支付状态",
          width: "76px",
          class: 'text-center',
          render : function(value){
            if(value == 0){
              return "未支付";
            }else if(value == 1){
              return "已支付";
            }else{
              return "";
            }
          }
        });
        aoColumns.push({
          data : "add_date",
          sortable : true,
          title : "下单时间",
          width: "128px",
          class: 'text-center',
          render : function(value){
            if(value){
              return winFn.formatDate(value,true);/*宽度width: "121px",*/
            }else{
              return "";
            }
          }
        });
        aoColumns.push({
          data : "pay_date",
          sortable : true,
          width: "128px",
          class: 'text-center',
          title : "付款日期",
          render : function(value){
            if(value){
              return winFn.formatDate(value,true);/*宽度width: "121px",*/
            }else{
              return "";
            }
          }
        });
        if(optsVisible){
          aoColumns.push({
            data : "_kid_",
            width : "100px",
            class : 'text-center',
            title : "<label style='color:#000;' title='单行操作'>操作选项</label>",
            sortable : false
          });
        }
        var columnDefs = [];
        columnDefs.push({
          targets : 0,//指定的列
          render : function(value,type,row,meta){
            return '<label >'+(meta.row < 9 ? '0'+(meta.row+1) : (meta.row+1))+'</label>';
          }
        });
        if(optsVisible){//是否来显示某列
          columnDefs.push({
            targets : -1,
            render : function(value,type,row,meta){
              var html = "<a href='javascript:thisPage.rowInfo(" + meta.row + ");' style='outline:none;text-decoration: none;color:#3b8cff;display:none' permission='order_manage_row_edit'>详情</a>";
              if(row.buyer_type == 1){
                html += "<a href='javascript:thisPage.rowCoupon(" + meta.row + ");' style='outline:none;text-decoration: none;color:#3b8cff;margin-left:4px;display:none' permission='order_manage_row_coupon_list'>优惠券</a>";
              }
              return html;
            }
          });
        }
        columnDefs.push({
          targets : [0,1,2,3,4,5,6,7,8,9],
          render : function(value,type,row,meta){
            return pageDataTable.formatColumn(value);
          }
        });
        columnDefs.push({
          visible : false,//列的隐藏显示
          targets : []//指定列索引
        });
        thisTable = pageDataTable.initDataTable({
          tableDom : tableDom,
          sAjaxSource : getList,
          fnServerParams : function(params){
            params.push(
              {"name":"buyerAccount","value":winFn.getDomValue('#key_buyer')},
              {"name":"payeeAccount","value":winFn.getDomValue('#key_payee')},
              {"name":"out_trade_no","value":winFn.getDomValue('#key_out_trade_no')},
              {"name":"date_start","value":winFn.getDomValue('#key_add_time_start') ? new Date(winFn.getDomValue('#key_add_time_start').replace(new RegExp("-","gm"),"/")).getTime()/1000 : ''},
              {"name":"date_end","value":winFn.getDomValue('#key_add_time_end') ? new Date(winFn.getDomValue('#key_add_time_end').replace(new RegExp("-","gm"),"/")).getTime()/1000 : ''}
            );
          },
          aoColumns : aoColumns,
          columnDefs : columnDefs,
          complete : function(settings,data){},
          footer : function(data,start,end,thLength){
            var allTotal = 0;
            for(var x=0;x<data.length;x++){
              allTotal += Number(data[x].total_fee)
            }
            var html = '<tr><td colspan="'+thLength+'" style="text-align:center;height:37px">当前页的合计：'+allTotal+'</td></tr>';
            $(tableDom +' tbody').append(html);
          },
          selected : function(selected){}
        });
        pageDataTable.buttons(thisTable);
        pageDataTable.action(thisTable);
        pageDataTable.select(thisTable, tableDom);
        pageDataTable.tooltip();
        $('.dataTables_scroll .dataTables_scrollBody').removeAttr('style');//解决dataTable表头下拉框被tbody遮挡
      },
      //双击事件
      trDblclick: function(data){
        if(data){
          thisPage.edit(data.kid);
        }
      },
      search: function(){
        if(verifyFn.inputCheck('#order_manage_btn_listData','没有操作权限')) return;
        $(tableDom + '_wrapper table input[type=checkbox]').prop('checked',false);
        thisTable.draw();
      },
      resetForm: function(){
        winFn.clearFormData('#form_goods_order_edit',[{'dropdownLabel_buyer_type':'选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）'}]);
      },
      edit: function(kid){
        thisPage.initDialogTable(kid);
      },
      //移除不需要对比的key(此方法可有可无)
      editJson : function(data,keys){
        if(keys){
          for(var h = 0; h < keys.length; h++){
            delete data[keys[h]];//删除key元素
          }
        }
        stateOriginal = data;
      },
      //对比是否已修改了值,仅需判断必填的字段，文件上传的字段单独处理
      filterValue : function(params){
        if(stateOriginal != null){
          var ignoreKeys = '';
          var requiredKeys = '';
          for(var so in stateOriginal){
            if(params[so] == stateOriginal[so]){
              delete params[so];
              if(ignoreKeys != ''){
                ignoreKeys += ','+so;
              }else{
                ignoreKeys += so;
              }
            }else{
              if(requiredKeys != ''){
                requiredKeys += ','+so;
              }else{
                requiredKeys += so;
              }
            }
          }
          if(ignoreKeys != ''){
            params['ignoreKeys'] = ignoreKeys;//记录后端忽略验证的key以,隔开的字符串,注意数据库字段是否允许为空,可参考项目law-backend的joins.html;law-backend的JoinsService的方法edit();
          }
          if(requiredKeys != ''){
            params['requiredKeys'] = requiredKeys;//记录后端必填验证的key以,隔开的字符串
          }
        }
      },
      openDialog: function(title, kid, map){
        var url = urlAdd;
        if(kid != null && kid.length > 0){
          url = urlEdit;
          if(verifyFn.inputNull('#order_manage_row_edit','没有编辑权限')) return;
        }else{
          if(verifyFn.inputNull('#order_manage_btn_add','没有添加权限')) return;
        }
        layerFn.addOrEdit(title,'#div_goods_order_edit', ['450px','600px'], function(layerIndex,layero){
          if(verifyFn.inputNull('#user_id','购买人|付费用户id不能为空')) return;
          if(verifyFn.inputNull('#buyer_type','请选择购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）')) return;
          if(verifyFn.inputNull('#openId','微信的openId不能为空')) return;
          if(verifyFn.inputNull('#out_trade_no','订单号不能为空')) return;
          if(verifyFn.inputNull('#total_fee','支付金额不能为空')) return;
          if(verifyFn.inputNull('#status','支付状态(0未支付;1已支付)不能为空')) return;
          if(verifyFn.inputNull('#evaluate','评价状态(0待评价;1已评价)不能为空')) return;
          if(verifyFn.inputNull('#refund','退款状态(0未退款;1已退款)不能为空')) return;
          if(verifyFn.inputNull('#version','版本号(乐观锁)不能为空')) return;
          if(verifyFn.inputNull('#body','支付描述（下单描述）不能为空')) return;
          if(verifyFn.inputNull('#add_date','下单时间不能为空')) return;
          var params = {
            user_id : winFn.getDomValue('#user_id',true),
            buyer_type : winFn.getDomValue('#buyer_type',true),
            openId : winFn.getDomValue('#openId',true),
            transaction_id : winFn.getDomValue('#transaction_id',true),
            out_trade_no : winFn.getDomValue('#out_trade_no',true),
            total_fee : winFn.getDomValue('#total_fee',true),
            status : winFn.getDomValue('#status',true),
            evaluate : winFn.getDomValue('#evaluate',true),
            refund : winFn.getDomValue('#refund',true),
            version : winFn.getDomValue('#version',true),
            body : winFn.getDomValue('#body',true),
            pay_date : new Date(winFn.getDomValue('#pay_date').replace(new RegExp("-","gm"),"/")).getTime()/1000,
            add_date : new Date(winFn.getDomValue('#add_date').replace(new RegExp("-","gm"),"/")).getTime()/1000,
            kid : kid
          };
          /*thisPage.filterValue(params);//检查是否已修改了数据,更新优化-选项3,如果没有上传功能则可以验证未修改任何值时则不提交
          var validTotal = 0;
          for(var ck in params){
            if(params[ck] != undefined){
              validTotal++;
            }
          }*/
          /*if(validTotal == 0){//没有文件上传时使用此段代码,更新优化-选项4
            layerFn.alert('尚未修改任何数据', AppKey.code.code199);
            return;
          }*/
          layerFn.submit(url,params,function(data){
            thisPage.complete(data,layerIndex,true);
          });
        });
        thisPage.resetForm();
        if(map != null){
          $.each(map.data,function(k,v){
            try{
              if(k == 'buyer_type'){
                winFn.editDropdown('#dropdownLabel_buyer_type','buyer_type' + v);
                return true;
              }
              $('#' + k).val(v);//若是有问题则把这个放在最前面
            }catch(e){}
          });
        }
      },
      rowEdit : function(rowIndex){
        var row = thisTable.row(rowIndex).data();
        thisPage.edit(row.kid);
      },
      //查看隐藏部分是全部内容,用法 render : function(value,type,row,meta){return thisPage.rowColumnView(value);}
      rowColumnView : function(value){
        if(value == null || value == undefined) return '';
        value = typeof value === 'string' ? value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') : value;
        var len = value.length;
        if(len > 30){
          return "<a href='javascript:layerFn.viewValue(\""+value+"\",\"430px\");' title='点击查看详情' style='outline:none;text-decoration: none;'>"+value.substring(0,30)+"…</a>";
        }else{
          return value;
        }
      },
      rowInfo: function(index){
        var row = thisTable.row(index).data();
        thisPage.initDialogTable(row.kid);
      },
      rowCoupon : function(index){
        authHandler('order_manage_row_coupon_list',function(){
          var row = thisTable.row(index).data();
          self.outTradeNo = row.out_trade_no;
          layerFn.queryGetHint(getOrderCouponList,{out_trade_no:row.out_trade_no},function(data){
            var isVisible = getOptsVisible('order_manage_btn_coupon_edit');
            thisPage.buildList(data.data);
            self.indexCoupon = layerFn.addOrEdit('订单号'+row.out_trade_no+'的优惠券列表','#div_list_coupon',['550px','450px'],function(layerIndex){
              layerFn.confirm('确定要停止全部优惠券兑换吗？',function(){
                thisPage.editAvailable(row.out_trade_no);
              });
            });
            $('#layui-layer'+self.indexCoupon+' a.layui-layer-btn0').text('全部停止').attr('title','全部停止发放优惠券');
            $('#layui-layer'+self.indexCoupon+' a.layui-layer-btn1').text('取消关闭');
            if(!isVisible){
              $('#layui-layer'+self.indexCoupon+' a.layui-layer-btn0').css('display','none');
              $('#layui-layer'+self.indexCoupon+' a.layui-layer-btn1').text('关闭');
            }
          });
        },function(){
          layerFn.alert('暂无查看权限',AppKey.code.code199);
        });
      },
      /*独立构建渲染,方便刷新*/
      buildList : function(list){
        var html = '';
        var isVisible = getOptsVisible('order_manage_btn_coupon_edit');
        for(var h=0;h<list.length;h++){
          var objs = list[h];
          html += '<tr>';
          html += '<td class="text-center">'+winFn.formatDate(objs.validity_start,true)+'</td>';
          html += '<td class="text-center">'+winFn.formatDate(objs.validity_end,true)+'</td>';
          var status = objs.status == 1;
          html += '<td class="text-center">'+(status ? '待核销' : '<span style="color:#33b45f">已核销</span>')+'</td>';
          var available = objs.available == 1;
          if(status){
            html += '<td class="text-center">'+(available ? '<span style="color:#33b45f">正常兑换</span>' : '停止兑换')+'</td>';
            if(isVisible){
              html += '<td class="text-center" title="'+(available ? '停止发放|禁用发放' : '正常发放|启用发放')+'"><a href="javascript:thisPage.editAvailable(\''+objs.kid+'\',\''+objs.available+'\');" style="text-decoration:none;outline:none;color:#3b8cff">'+(available ? '停止兑换' : '正常兑换')+'</a></td>';//objs.kid
            }else{
              html += '<td class="text-center"></td>';
            }
          }else{
            html += '<td class="text-center">停止兑换</td>';
            html += '<td class="text-center" title="已核销不可操作">不可操作</td>';
          }
          html += '</tr>';
        }
        $('#table_coupon_list tbody').html(html);
      },
      editAvailable : function(kid,available){
        if(available != null){
          var msg = '正常兑换';
          var target = 1;
          if(available == 1){
            msg = '停止兑换';
            target = 0;
          }
          layerFn.confirm('确定要<span style="color:#1e9fff">'+msg+'</span>操作吗？',function(){
            layerFn.submit(urlAvailable,{kid:kid,available:target},function(data){
              layerFn.queryGetHint(getOrderCouponList,{out_trade_no:self.outTradeNo},function(data){
                thisPage.buildList(data.data);
                thisPage.complete(data,null,false);
              });
            });
          });
        }else{
          layerFn.submit(urlAvailable,{out_trade_no:kid},function(data){
            layerFn.closedAll();
            thisPage.complete(data,null,false);
          });
        }
      },
      initDialogTable : function(kid){
        $('#accordion').empty();
        layerFn.queryByIdHint(urlQueryById, kid, function(data){
          layerFn.winRDom('查看详情','#div_order_info','680px',function(layerIndex,layero){},'关闭');
          var goodsOrder = data.data.goodsOrder || {};
          var orderDetails = data.data.orderDetails || [];
          var outTradeNo = goodsOrder.out_trade_no || '未知';
          var totalFee = goodsOrder.total_fee || '未知';
          var title = goodsOrder.title;
          var panel = "<div class='panel panel-default'><div class='panel-heading' role='tab' id='heading"+'One'+"'></div><div id='collapse"+'One'+"' class='panel-collapse collapse in' role='tabpanel' aria-labelledby='heading"+'One'+"'> </div> </div>";
          var panelTitle = "<h4 class='panel-title'><a style='outline:none;text-decoration:none;' class=\"collapsed\" role=\"button\" data-toggle=\"collapse\" data-parent=\"#accordion\" href=\"#collapseOne\" aria-expanded=\"false\" aria-controls=\"collapseOne\"><div class=\"row\"><div class=\"col-sm-6\"><div>订单编号："+outTradeNo+((title) ? "<br/><span style='font-size:14px;line-height:20px'>活动名称："+title+"</span>":"")+"</div></div><div class=\"col-sm-5 text-right\">销售额：￥"+totalFee+"</div></div></a></h4>";
          var panelBody = "<div class=\"panel-body\"></div>";
          $("#accordion").append(panel);
          $("#headingOne").append(panelTitle);
          $("#collapseOne").append(panelBody);
          for(var i = 0;j=orderDetails.length, i < j; i++){
            var panelBodyContent = "<div class=\"row\"><div class=\"col-sm-3 \"><img style=\"height:80px\" src=\""+webFiles+orderDetails[i].thumbnail+"\" alt=\"商品图片\" class=\"img-thumbnail img-responsive center-block\"></div>" +
              "<div class=\"col-sm-5\"><h4>"+orderDetails[i].contract_name+"</h4><span class=\"label label-primary\" style=\"line-height: 1.25 !important;\">"+orderDetails[i].goodsType+"</span></div>" +
              "<div class=\"col-sm-3\"><h5 class=\"text-right text-primary\">售价：￥"+orderDetails[i].item_fee+"</h5><p class=\"text-right text-muted\" style=\"font-size:14px\">数量："+orderDetails[i].total+ (orderDetails[i].bottles ? ('件 （'+orderDetails[i].bottles+'瓶/件）') : '瓶')+"</p></div>" +
              "</div>";
            if(j > 1){
              panelBodyContent = panelBodyContent + "<div style=\"height:10px\"></div>";
            }
            $("#collapseOne .panel-body").append(panelBodyContent);
          }
        });
      },
      complete: function(data,index,search){
        try{
          if(index){
            layerFn.closeIndex(index);
          }
          if(search){
            thisPage.search();
          }
          if(data){
            layerFn.handleResult(data.msg,data.code);
          }
        }catch(e){}
      }
    };
    thisPage.init();
    $('script').remove();
  })(jQuery);
</script>